<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <!-- 权限按钮拦截部分 -->
                            <%-- <button class="btn btn-sm btn-pink" id="import">导入</button>--%>
<%--                            <button class="btn btn-sm btn-info" id="query">上传文件</button>--%>
                            <span>
                                批次号 <input type="text" readonly="readonly"  id="batch-nums" />
                            </span>
                            <button class="btn btn-sm btn-success" id="edit">修改</button>
<%--                            <button class="btn btn-sm btn-danger" id="delete">删除</button>--%>
                                <button class="btn btn-info upload-btn btn-sm"><span class="glyphicon glyphicon-floppy-save"></span>下载导入模板</button>
                            <input type="file" class="form-control" id="btn-Excel" style="display: none">
                            <button class="btn btn-info btn-sm" id="displayExcel" onclick="document.getElementById('btn-Excel').click()">
                                导入子事项
                            </button>
<%--                            <button class="btn btn-success btn-sm" id="displayExce2" onclick="displayExce2()">--%>
<%--                                确认保存--%>
<%--                            </button>--%>
                            <%--<button class="btn btn-info btn-sm" onclick="alert('用户角色选择填写主要领导、分管领导、经办人');window.open('/user/downUserModle/')">--%>
                            <%--下载用户模板--%>
                            <%--</button>--%>
                            <!-- 权限按钮拦截部分 -->
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <div id="back-msg">校验信息：</div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <!-- dialog -->
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->

<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>

<script type="text/javascript">

    /**
     * 状态格式化
     */
    function stateFormatter(data) {
        switch (data) {
            case '01':
                return '未激活';
                break;
            case '02':
                return '正常';
                break;
            case '03':
                return '停用';
                break;
            default:
                return "无";
        }
    }

    //基本路径





    var baseUrl = "<s:url value="/excel/data/import"></s:url>/"

    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['',  '校验标志','备注','事项','牵头单位','协办单位', '周期类型', '时限','抄送领导'];
    //jqgrid表格中每一行的信息模型
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'flags', index: 'flags', width: 50, editable: true,formatter:excelStateValue},
        {name: 'remarks', index: 'remarks', width: 100, editable: true},
        {name: 'cell0', index: 'cell0', width: 160, editable: true},
        {name: 'cell1', index: 'cell1', width: 60, editable: true},
        {name: 'cell2', index: 'cell2', width: 60, editable: true},
        {name: 'cell3', index: 'cell3', width: 60, editable: true},
        {name: 'cell4', index: 'cell4', width: 60, editable: true},
        {name: 'cell5', index: 'cell5', width: 60, editable: true},
        // {name: 'batchNum', index: 'batchNum', width: 60, editable: true}
    ];
    //jqgrid的具体执行方法
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        rowNum:50,
        multiselect:false,
        onSelectRow: function () {

        }

    });


    function excelStateValue(data) {
        switch (data){
            case 0:
                return '校验不通过';
                break;

            case 1:
                return '校验通过';
                break

            default:
                return '无法校验';
        }
    }

    var rowids = [];//选中行id

    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    //加载查询对话框
    //$("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '查询对话框',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    var uerpicihao = 0;
    //更新操作
    $("#edit").click(function () {
            $.ajax({
                url:'/excel/data/getFailList?batchNum='+batchNum,
                dataType:'json',
                type:'get',
                contentType:'application/json',
                success:function (res) {
                    if(res.data.failList.length>0){
                        uerpicihao = 0;
                        sessionStorage.setItem("thefailList",uerpicihao);
                        console.log(sessionStorage.getItem("thefailList"))
                        loadDialog({
                            dialogTitle: '数据校验',
                            dialogUrl:"/excel/data/checkAndUpdate?batchNum="+batchNum,
                            dialogFoot:
                                '<button type="button" class="btn btn-pink" onclick="edit()">提交更新</button>' +
                                '<button type="button" class="btn btn-primary" onclick="nextUpdate()">查看下一条</button>' +
                                '<button type="button" class="btn btn-default" data-dismiss="modal" onclick="guanbi()">关闭 </button>'
                        });
                    }else{
                        alert("未导入文本或当前暂无需要修改的内容！")
                    }
                }
            });
        /*showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: "/excel/data/edit/",
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()">更新</button>' +
                // '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });*/
    });
    function guanbi(){
        console.log("关闭："+uerpicihao);
        console.log("关闭："+batchNum);
        var searchData={batchNum:batchNum}
        seachJqgirdData("#gridTable",searchData);
    }
    /**
     * 点击下一条；
     */
    function nextUpdate() {
        uerpicihao++
        sessionStorage.setItem("thefailList",uerpicihao);
    }

    //执行更新操作
    function edit() {
        executeSaveOrUpdate2({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: "/excel/data/edit/",
            tableId: "#gridTable",
            successMessage: "更新成功",
            successTitle: '更新提示框:',
          //  failMessage: '更新失败',
           // failFunc:showErrorDialog(obj),
            failTitle: '更新提示框:',
        });
    }
    //roomUser 查看或者 编辑 科室人员
   /* $("#roomUser").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("roomUser"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="updateRoonUser()">更新</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });*/

   /* function updateRoonUser() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("editroomuser"),
            tableId: "#gridTable",
            successMessage: "更新成功",
            successTitle: '更新对话框',
            failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }*/

    //删除
    $("#delete").click(function () {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    //显示创建对话框
    $("#create").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failTitle: '消息对话框'
        });
    }


    //导入excel
    /**
     *  导入Excel
     */
    var batchNum;
    $(document).on('change', "#btn-Excel", function () {
        var $this = $(this);
        var slgBtn = $(this).siblings("#displayExcel")
        var file = $(this).val();
        var formData = new FormData();
        formData.append("excelFile", $("#btn-Excel")[0].files[0]);
        $('.warning').css("display","block")
        $('.shade').css("display","block")
        $(".shade").fadeIn(100);
        $(".warning").fadeIn(100);
        $('.la-square-jelly-box').show();
        showShade();
        //警告框自定义内容
        $('.warning>.title>em').html('加载中……');
        if (file) {
            $.ajax({
                url: "/excel/data/importExcel",
                data: formData,
                type: "post",
                processData: false,
                contentType: false,
                success: function (data) {
                    console.log("导入操作返回数据")
                    console.log(data);
                    $('.warning>.title>em').html(data);
                    $this.remove();
                    slgBtn.before(
                        "<input type=\"file\" class=\"form-control\" id=\"btn-Excel\" style=\"display: none\">"
                    )
                    $("#batch-nums").val(data.data.batchNum);
                   console.log(data.data.batchNum)
                    var searchData ={batchNum:data.data.batchNum}
                        uerpicihao ={batchNum:data.data.batchNum}
                    batchNum=data.data.batchNum;
                    $("#back-msg").html("校验信息："+data.message)
                    seachJqgirdData("#gridTable",searchData);
                    setTimeout(function () {
                        $('.la-square-jelly-box').hide();
                        $('.warning').css("display","none")
                        $('.shade').css("display","none")
                    },500)
                }
            });
        } else {
            alert("导入失败")
        }
    });
    //从部门到科室
    var deptId = '${deptId}';
    var deptName = '${deptName}';
    if (deptId != "") {
    //    alert("查看“" + deptName + "”的科室详情");
        window.onpageshow = function () {
            var url = '/sys/deptRoom';
            //先清空条件,多次调用时查询条件会累加
            $('#gridTable').jqGrid('clearGridData');
            $("#gridTable").jqGrid('setGridParam', {
                url: url,
                datatype: 'json',
                postData: {'deptId': deptId}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        }
        $("#back").css("display","inline");
    }
    //返回部门
    $("#back").click(function () {
        window.location.href="/modules/sys/dept";
    });

</script>
<script>
    function displayExce2(){
        var r = confirm("提示：将保存校验通过的数据，校验不通过的数据不会被保存。确认保存吗？");
        if (r == true) {
            x = "您按了确认！";
            var batch_nums = document.getElementById("batch-nums").value
            if(batch_nums==""||batch_nums==undefined||batch_nums==NaN){
                alert("请先导入文件！")
            }else{
                console.log(batch_nums)
            }
        } else {
            x = "取消！";
        }
    }

    $(".upload-btn").on("click", function () {
        window.open("/taskMain/downModel/");
    })

</script>
</body>
</html>